home *** CD-ROM | disk | FTP | other *** search
/ Champak 43 / Vol 43.iso / games / penguin.swf / scripts / __Packages / Class / Control_cpu.as < prev    next >
Encoding:
Text File  |  2007-06-26  |  5.6 KB  |  214 lines

  1. class Class.Control_cpu extends Class.Control
  2. {
  3.    var hitRate;
  4.    var role;
  5.    var opp;
  6.    var side;
  7.    var bullet;
  8.    var meter_mc;
  9.    var angle;
  10.    var distance;
  11.    var startX;
  12.    var startY;
  13.    var onEnterFrame;
  14.    var startAngle;
  15.    var Vx;
  16.    var Vy;
  17.    var V;
  18.    var _V;
  19.    var distanceMax;
  20.    var blockTimes = 0;
  21.    function Control_cpu()
  22.    {
  23.       super();
  24.       if(_root.gameLevel < 2)
  25.       {
  26.          this.hitRate = 0.25;
  27.       }
  28.       else if(_root.gameLevel < 5)
  29.       {
  30.          this.hitRate = 0.35;
  31.       }
  32.       else if(_root.gameLevel < 8)
  33.       {
  34.          this.hitRate = 0.6;
  35.       }
  36.       else if(_root.gameLevel < 10)
  37.       {
  38.          this.hitRate = 0.7;
  39.       }
  40.       else if(_root.gameLevel < 15)
  41.       {
  42.          this.hitRate = 0.8;
  43.       }
  44.       else
  45.       {
  46.          this.hitRate = 0.9;
  47.       }
  48.       trace("hitRate: " + this.hitRate);
  49.    }
  50.    function init(_role, _opp, _side, _bullet)
  51.    {
  52.       this.role = _role;
  53.       this.opp = _opp;
  54.       this.side = _side;
  55.       this.bullet = _bullet;
  56.    }
  57.    function activeStart()
  58.    {
  59.       this.play();
  60.    }
  61.    function activeEnd()
  62.    {
  63.       this.meter_mc._x = -100;
  64.       this.meter_mc._y = -100;
  65.    }
  66.    function mouseDown()
  67.    {
  68.       this.angle = this.getAngle();
  69.       this.distance = this.getDistance();
  70.       var _loc6_ = _global.lToG(this.role);
  71.       this.meter_mc._x = _loc6_.x;
  72.       this.meter_mc._y = _loc6_.y - 120;
  73.       var _loc5_ = 180 + this.angle;
  74.       var _loc4_ = 5;
  75.       var mouseVx = _loc4_ * ExtMath.cosD(_loc5_);
  76.       var mouseVy = _loc4_ * ExtMath.sinD(_loc5_);
  77.       var f = int(this.distance / _loc4_) + 1;
  78.       this.startX = this.meter_mc._x;
  79.       this.startY = this.meter_mc._y;
  80.       _root.roleNow.setReady();
  81.       this.onEnterFrame = function()
  82.       {
  83.          this.meter_mc._x += mouseVx;
  84.          this.meter_mc._y += mouseVy;
  85.          this.mouseMove(this.meter_mc._x,this.meter_mc._y);
  86.          f--;
  87.          if(f == 0)
  88.          {
  89.             delete this.onEnterFrame;
  90.             this.mouseUp();
  91.          }
  92.       };
  93.    }
  94.    function getAngle()
  95.    {
  96.       var _loc4_ = ExtMath.distance(this.role._x,this.role._y,this.opp._x,this.opp._y);
  97.       var _loc3_ = Math.random();
  98.       if(_loc3_ < 0.2)
  99.       {
  100.          this.startAngle = -120 + int(Math.random() * 10 - 5) * 4;
  101.       }
  102.       else if(_loc3_ < 0.5)
  103.       {
  104.          this.startAngle = -130 + int(Math.random() * 10 - 5) * 4;
  105.       }
  106.       else if(_loc3_ < 0.7)
  107.       {
  108.          this.startAngle = -160 + int(Math.random() * 8 - 4) * 3;
  109.       }
  110.       else
  111.       {
  112.          this.startAngle = -130 + int(Math.random() * 8 - 4) * 3;
  113.       }
  114.       if(_root.mc.iceHill instanceof MovieClip)
  115.       {
  116.          if(_loc3_ < this.hitRate)
  117.          {
  118.             this.startAngle = -120 + int(Math.random() * 10 - 5);
  119.             trace("iceHill  startAngle: " + this.startAngle);
  120.          }
  121.       }
  122.       if(this.side == 1)
  123.       {
  124.          this.startAngle = - (this.startAngle + 180);
  125.       }
  126.       trace("startAngle: " + _loc3_ + "    " + this.startAngle);
  127.       return this.startAngle;
  128.    }
  129.    function getDistance()
  130.    {
  131.       var _loc3_ = ExtMath.distance(this.role._x,this.role._y,this.opp._x,this.opp._y);
  132.       trace("dis11111: " + _loc3_);
  133.       var _loc5_ = undefined;
  134.       var _loc7_ = Math.random();
  135.       trace("i::::::: " + _root.gameLevel + "   " + _loc7_ + "   " + this.hitRate);
  136.       if(_loc7_ < this.hitRate)
  137.       {
  138.          _loc5_ = int(Math.random() * 40 - 20);
  139.       }
  140.       else
  141.       {
  142.          _loc5_ = int(Math.random() * 10 - 5) * 80 + int(Math.random() * 60 - 30);
  143.          trace("      dis_offest: " + _loc5_);
  144.       }
  145.       _loc3_ += _loc5_;
  146.       trace("dis22222: " + _loc3_);
  147.       this.Vx = Math.sqrt(_loc3_ / 2 / _root.Vg / Math.abs(ExtMath.tanD(this.startAngle)));
  148.       if(this.side == 2)
  149.       {
  150.          this.Vx = - this.Vx;
  151.       }
  152.       var _loc8_ = _loc3_ / this.Vx;
  153.       this.Vy = _root.Vg * _loc8_ / 2;
  154.       if(this.side == 1)
  155.       {
  156.          this.Vy = - this.Vy;
  157.       }
  158.       var _loc6_ = _root.playControl.wind_lv * 5;
  159.       if(_loc6_ != 0 && !isNaN(_loc6_))
  160.       {
  161.          this.Vx -= _loc6_;
  162.       }
  163.       this.V = Math.abs(this.Vx / ExtMath.cosD(this.startAngle));
  164.       var _loc4_ = this.V / this._V * this.distanceMax;
  165.       trace("V: " + this.V);
  166.       trace("distance: " + _loc4_);
  167.       if(_loc4_ > this.distanceMax)
  168.       {
  169.          _loc4_ = this.distanceMax;
  170.       }
  171.       return _loc4_;
  172.    }
  173.    function checkHitIce()
  174.    {
  175.    }
  176.    function mouseMove(nowX, nowY)
  177.    {
  178.       this.distance = ExtMath.distance(nowX,nowY,this.startX,this.startY);
  179.       if(this.distance > this.distanceMax)
  180.       {
  181.          this.distance = this.distanceMax;
  182.       }
  183.       var _loc3_ = this.getPower(this.distance);
  184.       _root.roleNow.setAnimation(_loc3_);
  185.       this.meter_mc._x = nowX;
  186.       this.meter_mc._y = nowY;
  187.       this.meter_mc.point_mc._rotation = this.angle;
  188.       this.meter_mc.bar.mask_mc._rotation = int(this.distance / this.distanceMax * 180);
  189.       if(this.side == 1)
  190.       {
  191.          this.meter_mc.angle_txt.text = ExtMath.fixAngle(int(- this.angle)) + "┬░";
  192.       }
  193.       else
  194.       {
  195.          this.meter_mc.angle_txt.text = int(this.angle + 180) + "┬░";
  196.       }
  197.       this.meter_mc.power_txt.text = int(this.distance / this.distanceMax * 100) + "%";
  198.    }
  199.    function mouseUp()
  200.    {
  201.       this.startControl();
  202.    }
  203.    function getPower(distance)
  204.    {
  205.       var _loc2_ = distance / this.distanceMax;
  206.       return _loc2_;
  207.    }
  208.    function startControl()
  209.    {
  210.       this.play();
  211.       this.activeEnd();
  212.    }
  213. }
  214.